<template>
    <banner v-if="ads.type == 2" :ads="ads" @click="clkTrack"></banner>
    <info v-if="ads.type == 3" :ads="ads" @click="clkTrack"></info>
</template>

<script>
    import Banner from './AdsBanner.vue'
    import Info from './AdsInfo.vue'

    var sendPv = function (pv) {
        var img = new Image();
        img.src = pv;
    }

    var imgTrack = function (track) {
        if (typeof track === 'string') {
            sendPv(track);
        } else if (Object.prototype.toString.call(track) === '[object Array]') {
            var i = 0,
                    len = track.length;
            for (; i < len; i++) {
                sendPv(track[i]);
            }
        }
    }

    export default {
        name: 'AdsMedia',
        components:{
            Banner,
            Info,
        },
        props: {
            ads: Object
        },
        watch: {
            'ads': function (val) {
                let impr = val.impr_track;
                if(impr){
                    imgTrack(impr);
                }
            }
        },
        methods: {
            clkTrack: function () {
                let clk = this.ads.clk_track;
                if(clk){
                    imgTrack(clk)
                }
            }
        }
    }
</script>

<style>
    .x-tips{
        position: absolute;
        left: 15px;
        bottom: 5px;
        padding: 3px 6px;
        font-size: 12px;
        color: #fff;
        background-color: rgba(0, 0, 0, .5);
    }
</style>